package RegisterController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.renjun.smweb.commons.global.StaticCaches;
import com.renjun.smweb.commons.util.Encrypt;
import com.renjun.smweb.commons.util.Format;
import com.renjun.smweb.controller.RegisterController.RegisterController;
import com.renjun.smweb.dao.pojo.LoginInfo;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * Created by huamin on 2017/2/23.
 * 报名登记M6
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath*:/spring-mvc.xml", "classpath*:/spring-mybatis.xml"})
public class RegisterControllerTestCase {


    //模拟request,response
    private MockHttpServletRequest request;
    private static MockHttpServletResponse response;

    @Autowired
    private RegisterController registerController;

    @Before
    public void setUp() throws Exception {
        request = new MockHttpServletRequest();
        StaticCaches.setRealRootPath("D:\\IntelliJProject\\yeyzsxjhk\\yeyzsxj\\target\\yeyzsxj-1.0");
        System.out.println(StaticCaches.getRealRootPath());
        request.getSession().setAttribute("userinfo", getLoginInfo());
//        response = new MockHttpServletResponse();
    }
    /**
     *   获取缓存LoginInfo
     */
    private LoginInfo getLoginInfo() {
        LoginInfo loginInfo = new LoginInfo();
        loginInfo.setId("测试人员");
        loginInfo.setRoleid("2");
        loginInfo.setDistrictcode("310109");
        loginInfo.setRoletype("2");
        loginInfo.setUsername("测试123");
        loginInfo.setRealname("junit测试管理员");
        return loginInfo;
    }

    @Test
    public void testQueryRegisterList() {
        System.out.println("登记查询/查看登记列表");
        //封装参数
        Map<String,Object> params = new HashMap<>();
        params.put("id","7550be07-0f23-49f7-a220-c40cd99d1be1");
        params.put("userinfo",getLoginInfo());
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = registerController.queryRegisterList(request,response);
        String str = JSON.toJSONString(rs);
        String jiem = (String) rs.get("response");
        System.out.println("\n json对象：" +Encrypt.jiem(jiem));
    }

    @Test
    public void testRegisterDetail() {
        System.out.println("登记查询/查看单个登记列表");
        //封装参数
        Map<String,Object> params = new HashMap<>();
        params.put("id","1");
        params.put("userinfo",getLoginInfo());
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = registerController.registerDetail(request,response);
        String str = JSON.toJSONString(rs);
        String jiem = (String) rs.get("response");
        System.out.println("\n json对象：" +Encrypt.jiem(jiem));
    }

    @Test
    public void testModifyRegister() {
        System.out.println("登记查询/修改单个信息");
        //封装参数
        Map<String,Object> params = new HashMap<>();
        params.put("id","7550be07-0f23-49f7-a220-c40cd99d1be1");
        params.put("userinfo",getLoginInfo());
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = registerController.modifyRegister(request,response);
        String str = JSON.toJSONString(rs);
        String jiem = (String) rs.get("response");
        System.out.println("\n json对象：" +Encrypt.jiem(jiem));
    }

    @Test
    public void testRemoveRegister() {
        System.out.println("登记查询/删除单个信息");
        //封装参数
        Map<String,Object> params = new HashMap<>();
        params.put("id","1");
        params.put("xm","测试人员Junit");
        params.put("userinfo",getLoginInfo());
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = registerController.removeRegister(request,response);
        String str = JSON.toJSONString(rs);
        String jiem = (String) rs.get("response");
        System.out.println("\n json对象：" +Encrypt.jiem(jiem));
    }


    @Test
    public void testExportRegister() {
        System.out.println("登记查询/批量导出");
        //封装参数
        Map<String,Object> params = new HashMap<>();
        params.put("id","1");
        params.put("userinfo",getLoginInfo());
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = registerController.exportRegister(request,response);
        String str = JSON.toJSONString(rs);
        String jiem = (String) rs.get("response");
        System.out.println("\n json对象：" +Encrypt.jiem(jiem));
    }


    @Test
    public void testAddRegister() {
        System.out.println("登记/登记学生信息");
        //封装参数
        Map<String,Object> params = getRegister();
         params.put("userinfo",getLoginInfo());
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = registerController.addRegister(request,response);
        String str = JSON.toJSONString(rs);
        String jiem = (String) rs.get("response");
        System.out.println("\n json对象：" + Encrypt.jiem(jiem));
    }

    public Map<String,Object> getRegister() {
        Map<String,Object> registerMap = new HashMap<>();
        registerMap.put("ID", UUID.randomUUID().toString());//ID唯一标识
        registerMap.put("XM","张三");//姓名
        registerMap.put("csrq","20120203");//出生日期
        registerMap.put("xb","1");//性别是否需要转换
        registerMap.put("sfzlx","1");//身份证类型
        registerMap.put("sfzjh","430424201202031532");//证件号码
        registerMap.put("zjyxq","");//证件有效期
        registerMap.put("jzzlx","1");//居住证类型0	暂无，其他, 1	上海市居住证,  2	上海市海外人才居住证,L	上海市临时居住证
        registerMap.put("jzzhm","2222");//居住证号码
        registerMap.put("jzzyxq","20500203");//居住证有效期
        registerMap.put("mz","1");//名族
        registerMap.put("gjdq","156");//国家地区
        registerMap.put("jkzk","10");//健康状况 10	良好 20	一般
        registerMap.put("hjlb","2");//户籍类别      1	常驻 2	蓝印 3	外省市 4	港澳台侨 5	外籍 9	其他
        registerMap.put("fnhklx","1");//非农户口类型  1	城市 3	乡镇 2	县城
        registerMap.put("hksf","310000");//户口省份
        registerMap.put("hkqx","310116");//户口区县
        registerMap.put("hkrod","1");//户口路
        registerMap.put("hkz","2335");//户口所在的弄（组）
        registerMap.put("HKLDH","01");//户口所在的楼栋号
        registerMap.put("hks","427");//户口所在的室
        registerMap.put("hkjz","15137");//户口街镇
        registerMap.put("hkjwh","04008038");//户口居委/村
        registerMap.put("hjdjr","20010201");//户籍登记日
        registerMap.put("hzgx","1");//与户主关系
        registerMap.put("sfrhyz","1");//是否人户一致
        registerMap.put("xzzsf","310000");//现住址省市
        registerMap.put("xzzqx","310116");//现住址区县
        registerMap.put("xzzrod","1");//现居住路
        registerMap.put("xzzz","2335");//现住址所在的弄（组）
        registerMap.put("xzzldh","01");//现住址楼栋号
        registerMap.put("xzzs","428");//现住址室
        registerMap.put("xzzjd","15137");//现住址所属街道
        registerMap.put("xzzjw","04008038");//现住址所属居委
        registerMap.put("xzzyzbm","201201");//现住址邮编
        registerMap.put("lxdh","15136522365");//联系电话
        registerMap.put("txdz","上海市杨浦区开放大学");//通信地址
        registerMap.put("txdzyzbm","201201");//通信地址邮编
        registerMap.put("zfxz","4");//住房性质
        registerMap.put("czbh","110");//(产权房)产证编号
        registerMap.put("djrq","20160203");//(产权房)登记日期
        registerMap.put("cqfdz","上海市金山区");//(产权房)地址
        registerMap.put("htbh","");//(租赁)合同编号
        registerMap.put("qzrq","");//(租赁)起租日期
        registerMap.put("zfqt","");//住房其他
        registerMap.put("gfrgx","1");//与购房人关系
        registerMap.put("sffhjs","1");//是否符合计划生育政策
        registerMap.put("sfnmgtzzn","0");//是否农民工同住子女
        registerMap.put("sflqcjz","0");//是否领取残疾证
        registerMap.put("cjlb","");//残疾类别
        registerMap.put("cjzbh","");//残疾证编号
        registerMap.put("cjzfzrq","");//残疾证发证日期
        registerMap.put("cjzfzjg","");//残疾证发证机关
        registerMap.put("adduserid","超级测试人员");//添加人id，用户id
        registerMap.put("addtime", Format.getDateTime());//添加时间\
        registerMap.put("deleted","0");//删除位
        registerMap.put("djxx","上海开放大学幼儿园");//登记学校，学校代码
        registerMap.put("njdm","01");//登记年级代码
        registerMap.put("lqzt","0");//录取状态 默认：0待录取1学校录取2待统筹3区县统筹录取
        registerMap.put("JHRXM","测试监护人");//监护人姓名
        registerMap.put("jhrxb","2");//监护人性别
        registerMap.put("jhrgx","4");//与监护人关系
        registerMap.put("jhrdh","15124512541");//监护人电话
        registerMap.put("jhrzjlx","1");//监护人证件类型
        registerMap.put("jhrzjhm","430424197605061236");//监护人证件号码
        registerMap.put("jhrhksf","310000");//监护人户口省市
        registerMap.put("jhrqx","310116");//监护人户口区县
        registerMap.put("jhrxl","60");//监护人学历
        registerMap.put("jhrgzdw","上海开放大学");//监护人工作单位
        registerMap.put("jhrjzzlx","1");//监护人居住证类型
        registerMap.put("jhrjzzhm","");//监护人居住证号码
        registerMap.put("jhrjzzyxq","");//监护人居住证有效期
        registerMap.put("jhrsfbzf","1");//监护人是否标准分
        registerMap.put("jhrlssj","");//监护人临时居住证办证时间
        registerMap.put("JHRSFLHJY","1");//监护人是否灵活就业
        registerMap.put("JHRLHJYBH","110");//监护人灵活就业证编
        registerMap.put("JHRSYHYLB","1");//监护人就业行业类别
        registerMap.put("jydjcs","1");//监护人就业登记次数
        registerMap.put("ryyj","10");//入园依据 10	普通房产 20	经适房 30	廉租房 40	动迁 50	合法居住证明
        registerMap.put("ryyjlb","10");//入园依据类别 10	本地段户籍	10
        registerMap.put("syqk","1");//生源情况1	地段生2	非地段生
        return registerMap;
    }


    @Test
    public void testBatchGenerateRegistrationForm() {
        //参数{"xm":"张三"}
        request.setContent("{\"xm\":\"\"}".getBytes());
        //生成登记表
        JSONObject rs = registerController.batchGeneraterRegistrationForm(request, response);
        String jiem = Encrypt.jiem((String) rs.get("response"));
        System.out.println("json : " + jiem);
    }









}
